package com.nets.job;

import com.nets.client.Client;
import com.nets.packet.Packet;
import com.nets.packet.PacketType;
import com.nets.pool.ClientPool;
import com.nets.pool.QuartzPool;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.concurrent.TimeUnit;

/**
 * author sig
 * since 2017/2/22
 */
public class SimpleJob implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        Client client = ClientPool.create("127.0.0.1", 7081);
        Packet heartbeatReq = new Packet(PacketType.heartbeat);

        try {

            if (null != client) client.send(heartbeatReq);
            TimeUnit.MINUTES.sleep(1L);
        } catch (Exception e) {
            if (null != client) client.shutdown();
            System.exit(1);
        }
    }
}
